﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CourseUtils;

namespace ReadFile
{
    class Program
    {
        static void Main(string[] args)
        {
           
           int number = IOHelpers.ReadIntFromConsole("Enter the number", 1, 1000);

            StreamReader f = File.OpenText("F:\\C# courses\\NetElementaryMachJun2015\\YanaK\\ReadFile\\ReadFile\\ReadFile\\ValueKeys.txt");
            string line = null;
            Dictionary<int, double> myDictionary =new Dictionary<int, double>();
            while ((line = f.ReadLine()) != null)
            {
                Console.WriteLine(line);
                string[] array = line.Split('-');
                int key = Convert.ToInt32(array[0]);
                double value = Convert.ToDouble(array[1]);
                key = key - number;
                myDictionary.Add(key, value);
            }
            int minDistance = myDictionary.Min(p => p.Key);
            double targetValue = myDictionary[minDistance];
            Console.WriteLine(myDictionary);
            Console.WriteLine("Min distance {0}", minDistance);
            Console.WriteLine("Value {0}", targetValue);
            Console.ReadKey();
        }
    }
}
